<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>纯CSS轮播图 - Level 2</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
        user-select: none;
      }

      body {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      }

      .carousel-container {
        position: relative;
        width: 800px;
        height: 500px;
        overflow: hidden;
        border-radius: 20px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
      }

      .carousel-wrapper {
        display: flex;
        width: 400%;
        height: 100%;
        transition: transform 0.6s ease-in-out;
      }

      .carousel-item {
        width: 25%;
        height: 100%;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 48px;
        font-weight: bold;
        color: white;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        position: relative;
      }

      .carousel-item:nth-child(1) {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      }

      .carousel-item:nth-child(2) {
        background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
      }

      .carousel-item:nth-child(3) {
        background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
      }

      .carousel-item:nth-child(4) {
        background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
      }

      /* 隐藏单选框 */
      .radio-input {
        display: none;
      }

      /* 控制按钮 */
      .carousel-controls {
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 10px;
        z-index: 10;
      }

      .control-label {
        width: 12px;
        height: 12px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.5);
        cursor: pointer;
        transition: all 0.3s ease;
        border: 2px solid rgba(255, 255, 255, 0.8);
      }

      .control-label:hover {
        background: rgba(255, 255, 255, 0.8);
        transform: scale(1.2);
      }

      /* 当单选框被选中时，对应的指示器高亮 */
      #slide1:checked ~ .carousel-controls label[for="slide1"],
      #slide2:checked ~ .carousel-controls label[for="slide2"],
      #slide3:checked ~ .carousel-controls label[for="slide3"],
      #slide4:checked ~ .carousel-controls label[for="slide4"] {
        background: white;
        transform: scale(1.3);
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
      }

      /* 根据选中的单选框移动轮播图 */
      #slide1:checked ~ .carousel-wrapper {
        transform: translateX(0);
      }

      #slide2:checked ~ .carousel-wrapper {
        transform: translateX(-25%);
      }

      #slide3:checked ~ .carousel-wrapper {
        transform: translateX(-50%);
      }

      #slide4:checked ~ .carousel-wrapper {
        transform: translateX(-75%);
      }

      /* 左右箭头按钮容器 */
      .arrow-container {
        position: absolute;
        top: 50%;
        transform: translateY(-50%);
        width: 50px;
        height: 50px;
        z-index: 10;
      }

      .arrow-left-container {
        left: 20px;
      }

      .arrow-right-container {
        right: 20px;
      }

      /* 箭头样式 */
      .arrow {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        font-size: 24px;
        color: white;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
        opacity: 0;
        pointer-events: none;
      }

      .arrow:hover {
        background: rgba(255, 255, 255, 0.5);
        transform: scale(1.1);
      }

      /* 根据当前选中的单选框显示对应的箭头 */
      #slide1:checked ~ .arrow-left-container label[for="slide4"],
      #slide2:checked ~ .arrow-left-container label[for="slide1"],
      #slide3:checked ~ .arrow-left-container label[for="slide2"],
      #slide4:checked ~ .arrow-left-container label[for="slide3"] {
        opacity: 1;
        pointer-events: auto;
      }

      #slide1:checked ~ .arrow-right-container label[for="slide2"],
      #slide2:checked ~ .arrow-right-container label[for="slide3"],
      #slide3:checked ~ .arrow-right-container label[for="slide4"],
      #slide4:checked ~ .arrow-right-container label[for="slide1"] {
        opacity: 1;
        pointer-events: auto;
      }

      .title {
        position: absolute;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        color: white;
        font-size: 24px;
        font-weight: bold;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        z-index: 10;
      }

      /* 自动播放动画 */
      @keyframes auto-play {
        0%,
        20% {
          transform: translateX(0);
        }
        25%,
        45% {
          transform: translateX(-25%);
        }
        50%,
        70% {
          transform: translateX(-50%);
        }
        75%,
        95% {
          transform: translateX(-75%);
        }
        100% {
          transform: translateX(0);
        }
      }

      /* 默认自动播放 */
      .carousel-wrapper {
        animation: auto-play 12s infinite;
      }

      /* 当用户交互时暂停自动播放 */
      .carousel-container:hover .carousel-wrapper {
        animation-play-state: paused;
      }

      /* 当单选框被选中时，停止自动播放动画 */
      .radio-input:checked ~ .carousel-wrapper {
        animation: none;
      }
    </style>
  </head>
  <body>
    <div class="carousel-container">
      <input type="radio" name="carousel" id="slide1" class="radio-input" checked />
      <input type="radio" name="carousel" id="slide2" class="radio-input" />
      <input type="radio" name="carousel" id="slide3" class="radio-input" />
      <input type="radio" name="carousel" id="slide4" class="radio-input" />

      <div class="title">纯CSS轮播图 - Level 2</div>

      <div class="carousel-wrapper">
        <div class="carousel-item">Slide 1</div>
        <div class="carousel-item">Slide 2</div>
        <div class="carousel-item">Slide 3</div>
        <div class="carousel-item">Slide 4</div>
      </div>

      <!-- 左右箭头 -->
      <div class="arrow-container arrow-left-container">
        <label for="slide4" class="arrow">‹</label>
        <label for="slide1" class="arrow">‹</label>
        <label for="slide2" class="arrow">‹</label>
        <label for="slide3" class="arrow">‹</label>
      </div>

      <div class="arrow-container arrow-right-container">
        <label for="slide2" class="arrow">›</label>
        <label for="slide3" class="arrow">›</label>
        <label for="slide4" class="arrow">›</label>
        <label for="slide1" class="arrow">›</label>
      </div>

      <!-- 指示器 -->
      <div class="carousel-controls">
        <label for="slide1" class="control-label"></label>
        <label for="slide2" class="control-label"></label>
        <label for="slide3" class="control-label"></label>
        <label for="slide4" class="control-label"></label>
      </div>
    </div>
  </body>
</html>
